<template>
  <div class="front-home-container">
    <!-- 顶部导航栏 -->
    <header class="header">
      <div class="logo">
        <h1>旅游爱好者系统</h1>
      </div>
      <nav class="nav-menu">
        <router-link to="/front" class="nav-item">首页</router-link>
        <router-link to="/front/travel-announcement" class="nav-item">旅行公告</router-link>
        <router-link to="/front/forum" class="nav-item">交流论坛</router-link>
      </nav>
      <div class="user-info">
        <template v-if="token">
          <img :src="userInfo.avatar" alt="用户头像" class="user-avatar" style="width: 50px;border-radius: 50%;"></img>
          <span>{{ userInfo.nickName || userInfo.userName }}</span>
          <router-link to="/front/user-center" class="nav-item">个人中心</router-link>
          <el-button type="text" @click="logout">退出登录</el-button>
        </template>
        <template v-else>
          <router-link to="/login" class="nav-item">登录</router-link>
        </template>
      </div>
    </header>
    
    <!-- 主内容区 -->
    <main class="main-content">
      <router-view />
    </main>
    
    <!-- 页脚 -->
    <footer class="footer">
      <div class="footer-content">
        <p>© 2025 旅游爱好者系统 版权所有</p>
      </div>
    </footer>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useGlobalStore } from '../store/userInfo'
import { useRouter } from 'vue-router'
import { getUserInfo } from '@/request/login'

const store = useGlobalStore()
const getLoginInfo = async () => {
  try {
    const res = await getUserInfo();
     store.userInfo = res
    console.log('当前登录用户基本信息：',res)
  } catch (error) {
    console.log(error)
  }
}

getLoginInfo();


const router = useRouter()
const token = computed(() => store.token)
const userInfo = computed(() => store.userInfo)

// 退出登录
const logout = () => {
  store.token = ''
  store.userInfo = {}
  router.push('/login')
}
</script>

<style scoped>
.front-home-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 40px;
  height: 60px;
  background-color: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.logo h1 {
  margin: 0;
  font-size: 20px;
  color: #1890ff;
}

.nav-menu {
  display: flex;
  gap: 24px;
}

.nav-item {
  color: #333;
  text-decoration: none;
  padding: 8px 16px;
  border-radius: 4px;
  transition: all 0.3s;
}

.nav-item:hover {
  color: #1890ff;
  background-color: #f5f5f5;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 16px;
}

.main-content {
  flex: 1;
  margin-top: 60px;
  padding: 20px;
}

.footer {
  background-color: #f5f5f5;
  padding: 20px 0;
  text-align: center;
}
.user-avata{
  width: 50px;
  border-radius: 50%;
}
</style>